package com.community.controller;

import com.community.model.Notice;
import com.community.service.NoticeService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/Notice")
public class AdminNoticeInsertController extends HttpServlet {

        private NoticeService noticeService = new NoticeService();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String title = request.getParameter("title");
        String content = request.getParameter("content");
        Notice notice = new Notice();
        notice.setTitle(title);
        notice.setContent(content);
//调用service
        noticeService.publishNotice(notice);
        response.sendRedirect(request.getContextPath() + "/AdminNotice");
    }
}